# coding=utf-8
import requests
from login.shangdd_login import sdd_login_data
from src.common.dingding import send_ding
from src.common import log
import unittest
from src.common.readConfig import ReadConfig


class SddTest (unittest.TestCase):

    def setUp(self):
        global sdd_cookie, sdd_readconfig
        sdd_cookie = sdd_login_data ()
        sdd_readconfig = ReadConfig ("pre")
        self.case_name = " "

    def test_company(self):
        '''企业信息模块测试'''
        try:
            company_url = sdd_readconfig.get_url ("sdd_company_url")
            r1 = requests.get (company_url, cookies=sdd_cookie, timeout=15)
            result = r1.json ()
            print (result)
            self.assertEqual (result["code"], 0)
            if result["code"] == 0:
                log.logger_info.info ("商多多企业信息模块正常")
            else:
                send_ding ("商多多企业信息模块系统异常:" + str (result) + "@13058019302", "13058019302")
                log.logger_error.error (str (result))

        except Exception as ex:
            log.logger_error.error (ex)
            send_ding ("商多多企业信息模块异常:" + str (ex) + "@13058019302", "13058019302")
            raise Exception (str (ex))

    # @unittest.skip ("i don't want to run this case.")
    def test_getCompanyList(self):
        '''成员企业信息模块测试'''
        try:
            company_list_url = sdd_readconfig.get_url ("sdd_getcompanylist_url")
            r1 = requests.get (company_list_url, cookies=sdd_cookie, timeout=15)
            result = r1.json ()
            print (result)
            self.assertEqual (result["code"], 0)
            if result["code"] == 0:
                log.logger_info.info ("商多多成员企业信息模块正常")
            else:
                send_ding ("商多多成员企业信息模块系统异常:" + str (result) + "@13058019302", "13058019302")
                log.logger_error.error (str (result))

        except Exception as ex:
            log.logger_error.error (ex)
            send_ding ("商多多成员企业信息模块异常:" + str (ex) + "@13058019302", "13058019302")
            raise Exception (str (ex))

    def test_getIssueList(self):
        '''佣金通签发列表信息测试'''
        # self.skipTest ('do not run this.')
        try:
            issue_list_url = sdd_readconfig.get_url ("sdd_getIssue_url")
            r1 = requests.get (issue_list_url, cookies=sdd_cookie, timeout=15)
            result = r1.json ()
            print (result)
            self.assertEqual (result["code"], 0)
            if result["code"] == 0:
                log.logger_info.info ("佣金通签发列表信息模块正常")
            else:
                send_ding ("商多多佣金通签发列表信息模块系统异常:" + str (result) + "@13058019302", "13058019302")
                log.logger_error.error (str (result))

        except Exception as ex:
            log.logger_error.error (ex)
            send_ding ("商多多佣金通签发列表信息模块异常:" + str (ex) + "@13058019302", "13058019302")
            raise Exception (str (ex))

    def test_getConfirmList(self):
        '''佣金通保兑列表信息测试'''
        try:
            confirm_list_url = sdd_readconfig.get_url ("sdd_getConfirm_url")
            r1 = requests.get (confirm_list_url, cookies=sdd_cookie, timeout=15)
            result = r1.json ()
            print (result)
            self.assertEqual (result["code"], 0)
            if result["code"] == 0:
                log.logger_info.info ("佣金通保兑列表信息模块正常")
            else:
                send_ding ("商多多佣金通保兑列表信息模块系统异常:" + str (result) + "@13058019302", "13058019302")
                log.logger_error.error (str (result))

        except Exception as ex:
            log.logger_error.error (ex)
            send_ding ("商多多佣金通保兑列表信息模块异常:" + str (ex) + "@13058019302", "13058019302")
            raise Exception (str (ex))

    def test_register_company(self):
        '''成员企业注册测试'''
        try:
            confirm_list_url = sdd_readconfig.get_url ("sdd_getConfirm_url")
            r1 = requests.get (confirm_list_url, cookies=sdd_cookie, timeout=15)
            result = r1.json ()
            print (result)
            self.assertEqual (result["code"], 0)
            if result["code"] == 0:
                log.logger_info.info ("佣金通保兑列表信息模块正常")
            else:
                send_ding ("商多多佣金通保兑列表信息模块系统异常:" + str (result) + "@13058019302", "13058019302")
                log.logger_error.error (str (result))

        except Exception as ex:
            log.logger_error.error (ex)
            send_ding ("商多多佣金通保兑列表信息模块异常:" + str (ex) + "@13058019302", "13058019302")
            raise Exception (str (ex))
